package com.woniuxy.qiantai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.qiantai.entity.Address;
import com.woniuxy.qiantai.vo.Position;
import com.woniuxy.qiantai.mapper.AddressMapper;
import com.woniuxy.qiantai.mapper.PositonMapper;
import com.woniuxy.qiantai.service.AddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author firstGroup
 * @since 2023-02-22 09:45:58
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {
    @Autowired
    private AddressMapper addressMapper;

 /*   @Autowired
    private PositonMapper positonMapper;*/

    @Override
    public List<Address> selectAllAddress(Integer id) {
        QueryWrapper<Address> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", id);
        return addressMapper.selectList(queryWrapper);
    }

    @Override
    public void insertAddress(Integer userId, String[] area,String detailAddress, String receiveName, String tel) {
        //省市区 +详细地址 拼接
        StringBuilder addressContext=new StringBuilder();
        addressContext.append(area[0]).append(area[1]).append(area[2]).append(detailAddress);
        Address address= new Address();
       address.setUserId(userId);
       address.setAddress(new String(addressContext));
       address.setStatus(0);
       address.setTel(tel);
       address.setReceiveName(receiveName);
       address.setCreateTime(new Date());
        //System.out.println(address);
        addressMapper.insert(address);
    }
}
